package com.yx.utils;

import org.springframework.security.crypto.bcrypt.BCrypt;

/**
 * @Classname PasswordUtils
 * @Date 2021/07/14 16:12
 * @Author by yx
 * @Description : 密码加密解密 算法为BCrypt
 */
public class PasswordUtils {

    /**
     * @Author:yx
     * @return java.lang.String
     * @Date 2021/07/14 16:17
     * @param password
     * @Description: 加密算法,第二个参数为随机生成的唯一盐值
     **/
    public static String haspw(String password){
        return BCrypt.hashpw(password, BCrypt.gensalt());
    }

    /**
     * @Author:yx
     * @return java.lang.Boolean
     * @Date 2021/07/14 16:18
     * @param password
     * @param dbpassword
     * @Description: 密码比较,一样返回true,加密的密码本身携带了盐值
     **/
    public static Boolean checkpw(String password,String dbpassword){
        return BCrypt.checkpw(password, dbpassword);
    }
}
